<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://java.sun.com/jsf/html">

<p:outputPanel id="ctcPanel" layout="block" style="margin: 50px 0;">
    <div class="table-top-panel">
        <p:graphicImage value="../../resources/img/icons/contract.png"/>
        <p:outputLabel value="Contracte" styleClass="table-label"/>
    </div>
    <h:form id="ctc-formId">
        <p:dataTable id="ctcData" var="c" value="#{employmentDataBean.contracts}" editable="true"
                     emptyMessage="Nu sunt inregistrari pentru dosarul curent"
                     styleClass="data-table-style data-table-panel">

            <p:ajax event="rowEdit" listener="#{employmentDataBean.onContractDataEdit}"/>

            <p:column headerText="Principal" width="5%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{c.basic}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:selectBooleanCheckbox value="#{c.basic}"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Nr. contract" width="20%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{c.contractNr}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{c.contractNr}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Data contract" width="10%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{c.contractDate}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{c.contractDate}" showOn="button" required="true" styleClass="calendar-style"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Valabil din" width="10%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{c.fromDate}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{c.fromDate}" showOn="button" required="true" styleClass="calendar-style"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Valabil pana la" width="10%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{c.toDate}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{c.toDate}" showOn="button" required="true" styleClass="calendar-style"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Termen proba" width="20%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{c.trialPeriod}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{c.trialPeriod}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Actiuni" width="20%">
                <p:rowEditor id="ctc-row-editor"/>
                <p:commandLink value="Delete" actionListener="#{employmentDataBean.deleteContract(c)}"
                               update="ctcData"/>
            </p:column>

        </p:dataTable>

        <p:commandLink value="+ Adauga contract" actionListener="#{employmentDataBean.addNewContract('ctc-row-editor')}" update="@form" />
    </h:form>
</p:outputPanel>

<p:outputPanel id="caPanel" layout="block" style="margin: 50px 0;">
    <div class="table-top-panel">
        <p:graphicImage value="../../resources/img/icons/contract-agreement.png"/>
        <p:outputLabel value="Acorduri contracte" styleClass="table-label"/>
    </div>
    <h:form id="ca-formId">
        <p:dataTable id="caData" var="ca" value="#{employmentDataBean.contractAgreements}"
                     editable="true"
                     emptyMessage="Nu sunt inregistrari pentru dosarul curent"
                     styleClass="data-table-style data-table-panel">

            <p:ajax event="rowEdit" listener="#{employmentDataBean.onContractAgreementDataEdit}"/>

            <p:column headerText="Nr. acord" width="20%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{ca.agreementNumber}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{ca.agreementNumber}"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Data acord" width="20%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{ca.agreementDate}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{ca.agreementDate}" showOn="button" required="true" styleClass="calendar-style"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Descriere" width="40%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{ca.description}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputTextarea value="#{ca.description}" cols="58" rows="2" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Actiuni" width="20%">
                <p:rowEditor id="ca-row-editor"/>
                <p:commandLink value="Delete" actionListener="#{employmentDataBean.deleteContractAgreement(ca)}"
                               update="caData"/>
            </p:column>

        </p:dataTable>

        <p:commandLink value="+ Adauga acord contract" actionListener="#{employmentDataBean.addNewContractAgreement('ca-row-editor')}" update="@form"/>
    </h:form>
</p:outputPanel>

<p:outputPanel id="wePanel" layout="block" style="margin: 50px 0;">
    <div class="table-top-panel">
        <p:graphicImage value="../../resources/img/icons/work-experience.png"/>
        <p:outputLabel value="Experienta de munca" styleClass="table-label"/>
    </div>
    <h:form id="we-formId">

        <p:dataTable id="weData" var="we" value="#{employmentDataBean.workExperiences}"
                     editable="true"
                     emptyMessage="Nu sunt inregistrari pentru dosarul curent"
                     styleClass="data-table-style data-table-panel">

            <p:ajax event="rowEdit" listener="#{employmentDataBean.onWorkExperienceDataEdit}"/>

            <p:column headerText="Locul de munca">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{we.workPlace}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{we.workPlace}"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Functia">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{we.position}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{we.position}"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Inceput activitate">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{we.fromDate}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{we.fromDate}" showOn="button" required="true" styleClass="calendar-style"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Sfarsit activitate">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{we.toDate}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{we.toDate}" showOn="button" required="true" styleClass="calendar-style"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Categorie">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{we.jobCategory.name}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:selectOneMenu value="#{we.jobCategory}" required="true"
                                         style="width: 200px;" converter="#{objectMappingConverter}">
                            <f:selectItem itemLabel="Selectati categoria"/>
                            <f:selectItems var="wk" value="#{employmentDataBean.workCategories}" itemLabel="#{wk.name}"
                                           itemValue="#{wk}"/>
                        </p:selectOneMenu>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Actiuni" width="20%">
                <p:rowEditor id="we-row-editor"/>
                <p:commandLink value="Delete" actionListener="#{employmentDataBean.deleteWorkExperience(we)}"
                               update="weData"/>
            </p:column>

        </p:dataTable>

        <p:commandLink value="+ Adauga experienta de munca" actionListener="#{employmentDataBean.addNewWorkExperience('we-row-editor')}" update="@form"/>
    </h:form>
</p:outputPanel>

<p:outputPanel id="srPanel" layout="block" style="margin: 50px 0;">
    <div class="table-top-panel">
        <p:graphicImage value="../../resources/img/icons/wage.png"/>
        <p:outputLabel value="Salarizare" styleClass="table-label"/>
    </div>
    <h:form id="sr-formId">
        <p:dataTable id="srData" var="sr" value="#{employmentDataBean.salaries}"
                     editable="true"
                     emptyMessage="Nu sunt inregistrari pentru dosarul curent"
                     rowIndexVar="rowIndex" styleClass="data-table-style data-table-panel">

            <p:ajax event="rowEdit" listener="#{employmentDataBean.onSalaryDataEdit}"/>

            <p:column headerText="Gradul de salarizare">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{sr.salaryLevel.name}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:selectOneMenu value="#{sr.salaryLevel}" required="true"
                                         style="width: 200px;" converter="#{objectMappingConverter}">
                            <f:selectItem itemLabel="Selectati gradul"/>
                            <f:selectItems var="sl" value="#{employmentDataBean.salaryLevels}" itemLabel="#{sl.name}"
                                           itemValue="#{sl}"/>
                        </p:selectOneMenu>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Treapta de salarizare">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{sr.salaryStep.name}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:selectOneMenu value="#{sr.salaryStep}" required="true"
                                         style="width: 200px;" converter="#{objectMappingConverter}">
                            <f:selectItem itemLabel="Selectati treapta"/>
                            <f:selectItems var="ss" value="#{employmentDataBean.salarySteps}" itemLabel="#{ss.name}"
                                           itemValue="#{ss}"/>
                        </p:selectOneMenu>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Salariul de functie">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{sr.amount}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{sr.amount}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Data stabilirii">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{sr.establishmentDate}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{sr.establishmentDate}" showOn="button" required="true" styleClass="calendar-style"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Actiuni" width="20%">
                <p:rowEditor id="sr-row-editor"/>
                <p:commandLink value="Delete" actionListener="#{employmentDataBean.deleteSalary(sr)}"
                               update="srData"/>
            </p:column>

        </p:dataTable>

        <p:commandLink value="+ Adauga salariu" actionListener="#{employmentDataBean.addNewSalary('sr-row-editor')}" update="@form"/>
    </h:form>
</p:outputPanel>

</ui:composition>